<div class="modal-body no-p">
	<div class="row">
		<div class="col-xs-12">
			<section class="panel panel-primary no-b">
				<header class="panel-heading clearfix brtl brtr">
					<div class="overflow-hidden">
						<a href="javascript:;" class="h4 show no-m pt5">订单详情</a>
					</div>
				</header>

				<div id="formPrinter">
					<div class="table-form">
						<div class="h2">
							订单
						</div>
						<table>
							<tr>
								<td colspan="6" class="h5">订单信息</td>
							</tr>
							<tr>
								<td>订单编号</td>
								<td>{{order.order_no}}</td>
								<td>订单状态</td>
								<td>{{config.setup.orderStatus[order.status]}}</td>
								<td>创建时间</td>
								<td>{{order.create_time | datetime}}</td>

							</tr>
							<tr>

								<td>商品总金额</td>
								<td>{{order.goods_price}}</td>
								<td>配送费用</td>
								<td>{{order.express_fee}}</td>
								<td>订单总金额</td>
								<td>{{order.order_price}}</td>

							</tr>
							<tr>
								<td>积分抵扣</td>
								<td>{{order.integral_price}}</td>
								<td>优惠券抵扣</td>
								<td>{{order.coupon_price}}</td>
								<td>订单调价</td>
								<td><input type="text" value="{{order.discount}}" id="discount" class="form-control"/></td>
							</tr>
							<tr>
								<td>开票税费</td>
								<td>{% if order.is_invoice == 1%}{{order.tax}}{%else%}无发票 {%endif%}</td>
								<td>实际支付金额</td>
								<td colspan="5">{{order.real_price}}</td>
							</tr>
							<tr>
								<td>订单备注</td>
								<td colspan="5">{{order.remark}}</td>
							</tr>
							<tr>
								<td>管理员备注</td>
								<td colspan="5"><textarea name="admin_remark"  id="admin_remark" class="form-control">{{order.admin_remark}}</textarea></td>
							</tr>

						</table>
						
						{% if order.goods.length > 0 %}
						<table>
							<tr>
								<td colspan="7" class="h5">商品清单</td>
							</tr>
							<tr>
								<td>货号</td>
								<td>图片</td>
								<td>名称</td>
								<td>规格</td>
								<td>售价</td>
								<td>数量</td>
								<td>合计</td>

							</tr>
						
							
							{% for item in order.goods%}
							<tr>
								<td>{{item.goods_sn}}</td>
								<td><img src="{{item.list_pic_url}}" onclick="sublime.picture('{{item.list_pic_url}}')"/></td>
								<td>{{item.goods_name}}</td>
								<td>{{item.goods_specifition_name_value}}</td>
								<td>{{item.real_price}}</td>
								<td>{{item.number}}</td>
								<td>{{item.number*item.real_price}}</td>
								

							</tr>
							{% endfor %}
							
						</table>
						{% endif %}
						<table>
							<tr>
								<td colspan="5" class="h5">购买人</td>
							</tr>
							<tr>
								<td>ID</td>
								<td>用户名</td>
								<td>昵称</td>
								<td>手机号</td>
								<td>邮箱</td>

							</tr>
							<tr>
								<td>{{order.user.id}}</td>
								<td>{{order.user.username}}</td>
								<td>{{order.user.nickname}}</td>
								<td>{{order.user.mobile}}</td>
								<td>{{order.user.email}}</td>
							</tr>
						</table>
						<table>
							<tr>
								<td colspan="5" class="h5">收货人</td>
							</tr>
							<tr>
								<td>姓名</td>
								<td><input type="text" value="{{order.accept_name}}" class="form-control" id="accept_name"/></td>
								<td>手机号</td>
								<td><input type="text" value="{{order.mobile}}"  class="form-control" id="mobile"/></td>

							</tr>
							<tr>
								<td>地区</td>
								<td>
									<div class="row" id="region">
									<div class="col-md-3">
									<select name="country" id="country" class="form-control">
										{% for item in region.country%}
										<option value="{{item.id}}" {% if item.id == order.country_id %}selected{%endif%}>{{item.name}}</option>
										{% endfor%}
									</select>
									</div>
									<div class="col-md-3">
									<select name="province" id="province" class="form-control">
										{% for item in region.province%}
										<option value="{{item.id}}" {% if item.id == order.province_id %}selected{%endif%}>{{item.name}}</option>
										{% endfor%}
									</select>
									</div>
									<div class="col-md-3">
									
									<select name="city" id="city" class="form-control">
										{% for item in region.city%}
										<option value="{{item.id}}" {% if item.id == order.city_id %}selected{%endif%}>{{item.name}}</option>
										{% endfor%}
									</select>
									</div>
									<div class="col-md-3">
									
									<select name="district"  id="district" class="form-control">
										{% for item in region.district%}
										<option value="{{item.id}}" {% if item.id == order.district_id %}selected{%endif%}>{{item.name}}</option>
										{% endfor%}
									</select>
									</div>
									</div>
									</td>
								<td>邮编</td>
								<td><input type="text" value="{{order.zip}}"  class="form-control" id="zip"/></td>

							</tr>
							<tr>
								<td>地址</td>
								<td colspan="3"><input type="text" value="{{order.address}}"  class="form-control" id="address"/></td>
							</tr>
						</table>
					</div>

				</div>

			</section>

		</div>
	</div>
</div>
<div class="modal-footer">
	<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	<button onclick="save()" id="save" type="button" class="btn btn-primary" data-loading-text="正在提交...">提交</button>
</div>
<script type="text/javascript">
	function save(){

    var btn = $("#save");
    var dialog = $("#dialogDetail");
    btn.button("loading");
    $.post("/store/order/edit", {
    	id:{{order.id}},
    	orgin_discount:{{order.discount}},
    	real_price:{{order.real_price}},
    	discount: $("#discount").val(),
    	admin_remark: $("#admin_remark").val(),
    	accept_name: $("#accept_name").val(),
    	mobile: $("#mobile").val(),
    	country: $("#country").val(),
    	province: $("#province").val(),
    	city: $("#city").val(),
    	district: $("#district").val(),
    	address: $("#address").val(),
    	zip: $("#zip").val(),
    }, function (data) {
      if (data.errno == 0) {
        Toast.success("修改成功");
        dialog.modal("hide");
        datatable.ajax.reload();
      } else {
        Toast.error(data.errmsg);
      }
      btn.button("reset");

    }, "json");
  }
	$("select").change(function(e){
		
		var parentid = $(this).val();
		
		var index = $(this).parent().index();
		region(parentid,index);
		
	});
	
	function region(pid,index){
		var elem = $("#region").find("select");
		
		if(index >= elem.length-1){
			return;
		}
		$.post("/store/region/select", {
    	pid: pid
    }, function (data) {
     	console.log(data);
	    var areas =  data;
	    var html = "";
	    for (var i=0;i<areas.length;i++) {
	    	html += "<option value='"+areas[i].id+"'>"+areas[i].name+"</option>";
	    	
	    }
    	console.log(html)
   		index++;
     	elem.eq(index).html(html);
     
     
     	region(areas[0].id,index);
     
     

    }, "json");
	}
	
</script>